﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Entity;
using System.Data.Common;
using System.Data.Objects;

namespace MINERP.DAL.ShowDataControl
{
    public class DataControlDAL:DALBase
    {
        #region 删除指定的订单集合
        /// <summary>
        /// 删除指定的订单集合
        /// </summary>
        /// <param name="orderIds"></param>
        public void DelOrderBags(List<int> orderIds)
        {
            foreach (int orderId in orderIds)
            {
                Tb_OrderBag order = DataEntites.Tb_OrderBag.Where(p => p.OrderBagId == orderId).First();
                DataEntites.DeleteObject(order);
            }
            SaveDataChanges();
        }
        #endregion

        #region 获取指定订单下的产品集合
        /// <summary>
        /// 获取指定订单下的产品集合
        /// </summary>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public List<orderInfo> GetOrderInfoInOrderIds(List<int> orderIds)
        {
            List<orderInfo> ListProduct = new List<orderInfo>();
            foreach (int orderId in orderIds)
            {
                IQueryable<orderInfo> products = DataEntites.orderInfo.Where(p => p.Tb_OrderBag.OrderBagId == orderId);
                foreach (orderInfo p in products)
                {
                    ListProduct.Add(p);
                }
            }
            return ListProduct;
        }
        #endregion

        #region 获取指定产品下，指定流程ID下的流程集合
        /// <summary>
        /// 获取指定产品下，指定流程ID下的流程集合
        /// </summary>
        /// <param name="products"></param>
        /// <param name="techId"></param>
        /// <returns></returns>
        public List<WorkOrderFlowList> GetFlows(List<orderInfo> products, int techId)
        {
            List<WorkOrderFlowList> flows = new List<WorkOrderFlowList>();
            foreach (orderInfo pp in products)
            {
                IQueryable<WorkOrderFlowList> fs = DataEntites.WorkOrderFlowList.Where(p => p.orderInfo == pp&&p.tb_Tech.TechId==techId);
                foreach (WorkOrderFlowList f in fs)
                {
                    flows.Add(f);
                }
            }
            return flows;
        }
        #endregion

        #region 获取指定产品下所有的照片
        /// <summary>
        /// 获取指定产品下所有的照片
        /// </summary>
        /// <param name="products"></param>
        /// <returns></returns>
        public List<photoInfo> GetPhotoInProducts(List<orderInfo> products)
        {
            List<photoInfo> photos = new List<photoInfo>();
            foreach (orderInfo pp in products)
            {
                IQueryable<photoInfo> ps = DataEntites.photoInfo.Where(p => p.orderInfo == pp);
                foreach (photoInfo p in ps)
                {
                    photos.Add(p);
                }
            }
            return photos;
        }
        #endregion

        #region 提交改变
        public void SaveDataChanges()
        {
            Save();
        }
        #endregion
    }
}
